<!-- 修改密码表单 -->
<form class="layui-form model-form">
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">原始密码</label>
        <div class="layui-input-block">
            <input type="password" name="oldPsw" placeholder="请输入原始密码" class="layui-input"
                   lay-verType="tips" lay-verify="required|password" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">新密码</label>
        <div class="layui-input-block">
            <input type="password" name="newPsw" placeholder="密码由(a-zA-Z0-9)组成,6-30个字符" class="layui-input"
                   lay-verType="tips" lay-verify="required|password" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">确认密码</label>
        <div class="layui-input-block">
            <input type="password" name="rePsw" placeholder="请再次输入新密码" class="layui-input"
                   lay-verType="tips" lay-verify="required|equalTo" lay-equalTo="input[name=newPsw]" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block text-right">
            <button class="layui-btn" lay-filter="submit-psw" lay-submit>保存</button>
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </div>
</form>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;

        /* 表单验证 */
        form.verify({
            password:function (value,item) {
                if(!new RegExp("^[a-zA-Z0-9]{6,30}$").test(value)){
                    return '密码由(a-zA-Z0-9组合),6-30个字符';
                }
            }
        });

        // 监听提交
        form.on('submit(submit-psw)', function (data) {
            var loading = layer.load(3);
            $.ajax({
                url: "{{:url('Admin/editPassword')}}",
                type: 'post',
                dataType:'json',
                data: data.field,
                success: function (res) {
                    if (res.code != 0) {
                        layer.msg(res.msg, {icon: 5,time:1000});
                    } else {
                        layer.msg(res.msg, {icon: 1,time:1500});
                        admin.closeDialog('[lay-filter="submit-psw"]');
                    }
                    layer.close(loading);
                }, error: function () {
                    layer.msg('网络错误请稍后重试', {icon: 5,time:1000});
                    layer.close(loading);
                }
            });
            return false;
        });
    });
</script>
